package cn.kgc.crowdfundingadmin.controller;

import cn.kgc.crowdfundingadmin.pojo.Role;
import cn.kgc.crowdfundingadmin.service.RoleService;


import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class AssignController {
@Resource
    RoleService roleService;
@RequestMapping("/assign/to/assign/role/page")
public String toAssignRolePage(Integer adminId, Integer pageNum,Model model){
    //查询已分配角色
    List<Role> assignedRoleList = roleService.getAssignedRoleList(adminId);
    //查询未分配角色
    List<Role> unAssignedRoleList = roleService.getUnAssignedRoleList(adminId);

    //存储数据
    model.addAttribute("assignedRoleList",assignedRoleList);
    model.addAttribute("unAssignedRoleList",unAssignedRoleList);

    return "assign-role";
}
    @RequestMapping("/assign/role")
    public String assignRole(@RequestParam(value="roleIdList", required=false) List<Integer> roleIdList,
                             @RequestParam("adminId") Integer adminId,
                             @RequestParam("pageNum") String pageNum){

        //更新关系
        roleService.updateRelationship(adminId,roleIdList);


        return "redirect:/admin/query/for/search?pageNum="+pageNum;
    }
}
